package com.sky.mapper.user;

import com.github.pagehelper.Page;
import com.sky.dto.HistoryPageDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.pojo.Orders;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {
    /**
     * 新增订单
     * @param orders
     */
    void insert(Orders orders);

    /**
     * 查询超过15分钟处于待支付状态的订单
     * @param time
     * @return
     */
    @Select("select * from orders where order_time < #{time} and status = 1")
    List<Orders> getOverTimeOrders(LocalDateTime time);

    /**
     * 支付成功,修改订单状态
     * @param orders
     */
    void modifyOrderStatus(Orders orders);

    /**
     * 根据订单号查询订单
     */
    @Select("select * from orders where number = #{number};")
    Orders queryByNum(String number);

    /**
     * 分页查询历史订单
     * @param dto
     * @param userId
     * @return
     */
    Page<Orders> queryHistoryOrders(HistoryPageDTO dto, Long userId);

    /**
     * 查询订单详情
     * @param orderId
     * @return
     */
    @Select("select * from orders where id = #{orderId}")
    Orders queryOrderDetail(Long orderId);

    /**
     * 查询订单
     * @param id
     * @return
     */
    @Select("select * from orders where id = #{id};")
    Orders queryById(Long id);

    /**
     * 分页查询订单
     * @param dto
     * @return
     */
    Page<OrderVO> pageQuery(OrdersPageQueryDTO dto);

    /**
     * 各状态订单数统计
     * @return
     */
    OrderStatisticsVO orderStatusCount();
}
